// pages/editBusiness/editBusiness.js
import {editBusiness} from "../../ajax/module/userInfo.js"
let app=getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
     titleArr:[
       {
       id:"1",
       name:"店铺简称"
       },
       {
        id:"2",
        name:"客服电话"
        },
        {
          id:"3",
          name:"联系姓名"
          },
          {
            id:"4",
            name:"联系方式"
            },
            {
              id:"5",
              name:"店铺简介"
              },
              {
                id:"6",
                name:"营业执照"
                },

    ],
    title:"",
    content:"",
    id:"",

    shopName:"",
    customerTel:"",
    contactUser:"",
    contactPhone:"",
    storeIntroduction:"",

    associatedLicense:{}

    
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
      console.log(options.name)
      //  app.globalData.associatedLicense
      /**
       * 营业执照  6
       * 店铺简介  5
       * 联系方式  4
       * 联系姓名  3
       * 客服电话  2
       * 店铺简称  1
       */
      // if(options.id == "1"){
        this.setData({
          title:this.data.titleArr.filter(item=>{
            return item.id == options.id
          })[0].name,
          id:options.id,
          content: options.name == "未设置" ? "" : options.name,
          associatedLicense:app.globalData.associatedLicense
        })
      // }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },
  sureSave(){
     if(this.data.id == "1"){
        if(this.data.content.length<=15){
          editBusiness({shopName:this.data.content}).then(res=>{
            wx.showToast({
              title: '修改成功',
              duration:2000,
              icon:"none",
              success:()=>{
                    wx.navigateBack()
              }
            })  
          })
        }else{
          wx.showToast({
            title: '不能超过15个文字',
            icon:"none"
          })
        }
              
     }
     if(this.data.id == "2"){
      editBusiness({customerTel:this.data.content}).then(res=>{
        wx.showToast({
          title: '修改成功',
          duration:2000,
          icon:"none",
          success:()=>{
               wx.navigateBack()
          }
        })
      
     })
     }
     if(this.data.id == "3"){
         if(this.data.content.length <= 15){
          editBusiness({contactUser:this.data.content}).then(res=>{
            wx.showToast({
              title: '修改成功',
              duration:2000,
              icon:"none",
              success:()=>{
                  wx.navigateBack()
              }
            })
          
          })
        }else{
          wx.showToast({
            title: '不能超过15个文字',
            icon:"none"
          })
        }
             
     }
     if(this.data.id == "4"){
       console.log(this.data.contactPhone)
      if(this.data.content.length == 11){
        editBusiness({contactPhone:this.data.content}).then(res=>{
          wx.showToast({
            title: '修改成功',
            duration:2000,
            icon:"none",
            success:()=>{
                 wx.navigateBack()
            }
          })
        
         })
      }else{
        wx.showToast({
          title: '电话号码错误',
          duration:2000,
          icon:"none",
        })
      }
      
     }
     if(this.data.id == "5"){
      editBusiness({storeIntroduction:this.data.content}).then(res=>{
        wx.showToast({
          title: '修改成功',
          duration:2000,
          icon:"none",
          success:()=>{
               wx.navigateBack()
          }
        })
      
     })
     }
     
     
  },
  bindListen(e){
    function filteremoji(content){
      var ranges = [
          '\ud83c[\udf00-\udfff]',
          '\ud83d[\udc00-\ude4f]',
          '\ud83d[\ude80-\udeff]'
      ];
      let emojireg = content.replace(new RegExp(ranges.join('|'), 'g'), '');
      return emojireg;
    }
    let content=e.detail.value
    console.log(content)
    if(this.data.id == "1"){
       this.setData({
        content:filteremoji(content)
       })
    } 
    if(this.data.id == "2"){
      //
      this.setData({
        content:content
       })
    } 
    if(this.data.id == "3"){
      this.setData({
        content:content
       })
    } 
    if(this.data.id == "4"){
      this.setData({
        content:content
       })
    } 
    if(this.data.id == "5"){
      
      this.setData({
        content:filteremoji(content) 
       })
    } 
    


  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})